//
//  WPFSliderView.m
//  WPFMusicPlayer
//
//  Created by 王鹏飞 on 16/8/28.
//  Copyright © 2016年 王鹏飞. All rights reserved.
//

// 忽略前缀
#define MAS_SHORTHAND
// 集中装箱  基本数据类型转换成对象
#define MAS_SHORTHAND_GLOBALS
#import "WPFSliderView.h"
#import "Masonry.h"
#import "WPFTimeTool.h"

@interface WPFSliderView ()

@property (nonatomic,weak) UIImageView *bgImageView;

@property (nonatomic,weak) UILabel  *timeLabel;

@property (nonatomic,weak) UILabel  *tipLabel;

@property (nonatomic,weak) UIButton  *playBtn;
@end


@implementation WPFSliderView

- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self setUp];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setUp];
    }
    return self;

}

- (void)setUp {
    // 初始化控件
    UIImageView *bgImageView = [[UIImageView alloc] init];
    self.bgImageView = bgImageView;
    [self addSubview:bgImageView];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 95, 0, 90, 30)];
    view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    view.layer.cornerRadius = 15;
    view.layer.masksToBounds = YES;
    [self addSubview:view];
    
    UIButton *playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.playBtn = playBtn;
    [playBtn addTarget:self action:@selector(playBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:playBtn];
    playBtn.frame = CGRectMake(60, 3, 25, 25);
    [playBtn setBackgroundImage:[UIImage imageNamed:@"icon_zimu_defaults"] forState:UIControlStateNormal];
    
    UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 50, 20)];
    self.timeLabel = timeLabel;
    timeLabel.textColor = [UIColor whiteColor];
    timeLabel.font = [UIFont systemFontOfSize:14];
    [view addSubview:timeLabel];
    // 添加约束
    bgImageView.frame =  CGRectMake(0, 14, SCREEN_WIDTH - 100, 2);

    // 设置属性
    bgImageView.image = [UIImage imageWithColor:[UIColor colorWithHex:@"#32C5FF"]];
    
    timeLabel.text = @"00:00";
}

- (void)setTime:(NSTimeInterval)time {
    _time = time;
    self.timeLabel.text = [WPFTimeTool stringWithTime:time];
    
}

- (void)playBtnClick {
    [[ICMusicPlayManager sharedManager] seekToTime:self.time completionHandler:^(BOOL finished) {
            
    }];
}
@end
